﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using RiskMan.DataClass.Models.Plaza_II;

namespace RiskMan.DataClass.Models.Indikators
{
    class IndikatorPivot
    {
        /// <summary>
        /// Расчет индикатора Pivot
        /// </summary>
        /// <param name="coll"></param>
        /// <param name="init"></param>
        /// <param name="pivotParamLefgt"></param>
        /// <param name="pivotParamRight">HIGH или LOW</param>
        /// <param name="HighLow"></param>
        public bool Calculation(ObservableCollection<TestCalculationIndikators> coll, int indexCol, int init, int pivotParamLefgt, int pivotParamRight, string HighLow)
        {
            bool result = true;
            if (init < indexCol && coll.Count>indexCol+pivotParamRight)
            {
                for (int j = 0; j < pivotParamLefgt; j++)
                {
                    if (HighLow == "HIGH")
                    {
                        if (coll[indexCol - j - 1].Last > coll[indexCol].Last)
                            result = false;
                    }
                    if (HighLow == "LOW")
                    {
                        if (coll[indexCol - j - 1].Last < coll[indexCol].Last)
                            result = false;
                    }
                }

                for (int j = 0; j < pivotParamRight; j++)
                {
                    if (HighLow == "HIGH")
                    {
                        if (coll[indexCol + j + 1].Last >= coll[indexCol].Last)
                            result = false;
                    }
                    if (HighLow == "LOW")
                    {
                        if (coll[indexCol + j + 1].Last <= coll[indexCol].Last)
                            result = false;
                    }
                }
            }
            else
            {
                result=false;
            }
            return result;
        }
    }
}
